package commonUtility;
import java.net.*;
import java.util.*;

/**
 * Questa classe prende in ingresso il nome dell'interfaccia di rete della macchina, della
 * quale si vuole sapere l'indirizzo IP.
 * @author alex
 */

public class NetworkInterfaceIP {
		
	public String getInterfacesIp (String interfaceName){  
		NetworkInterface net = null;
		String ip = null;
		try {
			net = NetworkInterface.getByName(interfaceName);

		} catch (SocketException e1) {
			e1.printStackTrace();
		}
		Enumeration<InetAddress> e = net.getInetAddresses(); 
		while (e.hasMoreElements()){
			e.nextElement();
			InetAddress ip2 = (InetAddress) e.nextElement();
			ip = ip2.getHostAddress();
			//   System.out.println("IP address: "+ ip);
		}
		return ip;


	}
	
	/**
	 * @author erond
	 * @return Enumeration<NetworkInterface> lista delle interfacce di rete connesse e disponibili
	 */
	public Enumeration<NetworkInterface> getAvailableNetworkInterfaces(){
		Enumeration<NetworkInterface> interfaces = null;
		try {
			interfaces = NetworkInterface.getNetworkInterfaces();
		} catch (SocketException e) {
			e.printStackTrace();
		}
		return interfaces;
	}

	public static void main(String[] args) {
	//	NetworkInterfaceIP ip = new NetworkInterfaceIP();
}
}
